home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / v12n12.zip / PCMCVT.ZIP / PCMASM.ZIP / AMICONV.INC next >
Text File  |  1993-05-22  |  9KB  |  244 lines

  1. ;AMICONV.INC
  2. ;Copyright (c) 1993 Jay Munro
  3. ;First Published in PC Magazine June 29 1993
  4. ;PCMCVT Conversion module for AMIPro 2.x
  5.  
  6. ;Variables used by AMICONV
  7.    LastCharacter    DW  ?               ;last character value
  8.    CharCounter      DW  ?               ;character counter
  9.  
  10. AMIProCVT Proc Near
  11.  
  12. ReadAMIFile:
  13.     Call   AMIReadIt                    ;go read the file
  14.     Jc     AmiErrorLeap                 ;error, bag out immediately
  15.  
  16. ;---- This section searches for the key word [edoc] which signals the start
  17. ;     of the text
  18.  
  19. SearchLoop:                             ;find the start of the file
  20.     Push  BX
  21.     Invoke SearchString, 1, Addr ReadBuffer, BufferSize, Addr AmiEdoc, 6
  22.     Or    AX,AX
  23.     Jnz   AMIFilter                     ;got a match, start moving.
  24.     Mov   AX,BufferSize
  25.     Pop   BX                            ;BX contains current write count
  26.     Sub   AX,6                          ;back up to besure to get whole match
  27.     Js    AmiErrorLeap                  ;oops something went wrong.
  28.     Call  AdjustFilePtr                 ;slide file pointer up (6 chars back)
  29.     Jc    AmiErrorLeap
  30.     Jmp   ReadAMIFile
  31.  
  32. AmiErrorLeap:
  33.     Jmp   AMIExit
  34.     
  35. ;--- This section starts filtering text from control chars
  36.     
  37. AMIFilter:
  38.     Add   AX,5                          ;start just after [edoc] string (6)
  39.     Lea   SI,ReadBuffer                 ;get address of read buffer
  40.     Add   SI,AX                         ;add offset of [edoc]
  41.     Mov   CX,BufferSize
  42.     Sub   CX,AX
  43.     
  44. RAMILoop:                               
  45.     LodSb                               ;grab a character
  46.     Cmp    AL,'>'                       ;is it the end of the line?
  47.     Jnz    @F
  48.     Mov    AL,-1                        ;a bad read, quit now
  49.     Call   AMIWrite                     ;flush buffer
  50.     Jmp    APExitLeap                   ;yes out now
  51. @@:
  52. ;--Check for <> command
  53.     Cmp    AL,'<'                       ;start of a command?
  54.     Jnz    AtLoop                       ;jump ahead to check more
  55.     Dec    CX                           ;count it
  56.     Jnz    @F                           ;if CX = 0 then we're out of characters
  57.     Call   AMIReadIt                    ;go back for a new read
  58.     Jnc    @F
  59.  
  60. APExitLeap:
  61.     Jmp    AMIExit                      ;if out of characters then exit
  62.  
  63. @@:
  64.     Cmp    Byte Ptr [SI],'<'            ;ok, if next one is, then we're not in a command
  65.     Jz     AA1                          ;yes, then use it
  66.     Cmp    Byte Ptr [SI],';'            ;is it a a reverse one?  
  67.     Jnz    ACmdLoop                     ;no skip ahead
  68.     Inc    SI                           ;yes skip semicolon
  69.     Dec    CX                           ;count the character
  70.     Jnz    @F                           ;still have characters in buffer?
  71.     Call   AMIReadIt                    ;no read more
  72.     Jnc    @F                           ;read ok, keep going
  73.     Jmp    AMIExit                      ;read not good, exit
  74. @@:
  75.     LodSb
  76.     Jmp    AWrite                       ;skip it if it's a double
  77.     
  78. AA1:
  79.     Inc    SI
  80.     Jmp    AWrite                       ;skip it if it's a double
  81.  
  82. ACmdLoop:                               ;AMI commands within < >
  83.     LodSb
  84.     Cmp    AL,'>'                       ;did we hit the other end?
  85.     Jz     ASkip
  86.     Loop   ACmdLoop
  87.     Call   AMIReadIt                    ;go read the file
  88.     Jc     APExitLeap     
  89.     Jmp    ACmdLoop                     ;go back for more
  90.     
  91. ASkip:
  92.     Jmp    AMIReloop
  93.  
  94. AtLoop:                                 ;other commands surrounded by @ signs
  95.     Cmp    AL,'@'                       ;ok, is it an at sign?
  96.     Jnz    AMCRLF                       ;no, keep looking at it
  97.     Dec    CX                           ;count the character
  98.     Jnz    @F                           ;if still characters left, jump ahead
  99.     Call   AMIReadIt                    ;read some more characters
  100.     Jc     APExitLeap                   ;no more to read, quit now
  101.     
  102. @@:                                     ;loop until end of @ stuff
  103.     Cmp    Byte Ptr [SI],'@'            ;check next one
  104.     Jnz    AA
  105.     Inc    SI
  106.     Jmp    AMCRLF
  107.  
  108. AA:
  109.     LodSb
  110.     Cmp    AL,'@'
  111.     Jz     AMIReLoop
  112.     Loop   AA
  113.     Call   AMIReadIt                    ;go read the file
  114.     Jc     APExitLeap
  115.     Jmp    AA                           ;go back for more
  116.  
  117. AMCRLF:
  118.     Cmp    AL,13                        ;a carriage return?
  119.     Jz     APCheckCRLF
  120.                                         ;check line per graf
  121.     Cmp    AL,9                         ;tab character
  122.     Jnz    @F
  123.     Call   DoTabs                       ;expand the tabs
  124.     Jmp    AMIReLoop                    ;bag out
  125.     
  126. @@:
  127.     Cmp    AL,31                        ;ok, skip the rest
  128.     Jbe    AMIReLoop                       ;skip it
  129.     Or     AL,AL                        ;is it a zero...not cool
  130.     Jz     AMIReLoop                    ;yes, skip it
  131.     Jmp    AWrite                       ;otherwise write it.
  132.  
  133. APCheckCRLF:                            ;check crlf
  134.     Cmp    Word Ptr CRLF_FLAG,-1
  135.     Jz     AWrite                       ;yes, then ignore them.
  136.     Call   APEatCRLF
  137.     Jc     APExitLeap
  138.     Jmp    AMIReLoop
  139.  
  140. AWrite:                                 ;write what's left
  141.     Call   AMIWrite                     ;call our local write module
  142.     Jc     APExitLeap
  143.  
  144. AMIReLoop:
  145.     Loop   AMIReLeap
  146.     Call   AMIReadIt                    ;go read the file
  147.     Jnc    AMIReLeap                    ;skip ahead
  148.     Jmp    AMIExit                      ;jump out if we got an error
  149.     
  150. AMIReLeap:
  151.     Jmp    RAMILoop                     ;go back for more
  152.  
  153. AMIWrite:
  154.     Call   WriteIt                      ;no, then write it
  155.     RetN
  156.  
  157. AMIReadIt:
  158.     Call   ReadIt                       ;go read the file
  159.     Jnc    @F                           ;out and out error!
  160.     Or     BX,BX                        ;do we have anything to write?
  161.     Jz     A1                           ;nothing to write, skip out
  162.     Mov    AL,-1                        ;a bad read, quit now
  163.     Call   AMIWrite                     ;flush buffer
  164. A1:
  165.     Stc
  166. @@:
  167.     RetN
  168.  
  169. AdjustFilePtr:                          ;sets file pointer to another position
  170.     Add   Word Ptr FilePointer,AX
  171.     Adc   Word Ptr FilePointer[2],0     ;add buffer to file pointer
  172.     Push  BX
  173.     Invoke  Seek, SHandle, FilePointer  ;move pointer up
  174.     Pop   BX
  175.     RetN
  176.  
  177. CheckCX:
  178.     Jcxz  @F
  179.     RetN
  180. @@:                                     ;cx = 0, go read more
  181.     Call   AMIReadIt                    ;go read the file
  182.     RetN
  183.  
  184. APEatCRLF:                   ;--- Eats excess CRLF's in .SAM file
  185.     Mov    LastCRLF,1
  186.     Dec    CX                           ;ok, count it
  187.     Call   CheckCX
  188.  
  189. NextCRLF:
  190.     LodSb
  191.     Cmp    AL,13
  192.     Jnz    @F
  193.     Inc    LastCRLF                     ;register another one
  194.     Loop   NextCRLF                     ;loop back and keep eatin'
  195.     Call   CheckCX                      ;ran out of characters
  196.     Loop   NextCRLF                     ;got more, loop back
  197.  
  198. @@:
  199.     Cmp    AL,10                        ;ok, was it a LF?
  200.     Jnz    APCRWrite                    ;done deal, check things out
  201.     Loop   NextCRLF                     ;loop back and keep eatin'
  202.     Call   CheckCX                      ;ran out of characters
  203.     Loop   NextCRLF                     ;got more, loop back
  204.     Jmp    AMIExit
  205.  
  206. APCRWrite:
  207.     Dec    Word Ptr LastCRLF
  208.     Js     APCRExit
  209.     Mov    LastCharacter,AX
  210.     Mov    CharCounter,CX
  211.     Mov    CX,LastCRLF                  ;get number of CRLF's
  212.     Jcxz   SkipCRLF                     ;
  213.     
  214. SendCRLF:
  215.     Mov    AL,13                        ;cr
  216.     Call   AMIWrite                     ;call our local write module
  217.     Jc     APCRErrExit                  ;error time!
  218.     Mov    AL,10                        ;lf
  219.     Call   AMIWrite                     ;call our local write module
  220.     Jc     AMIExit                      ;error time!
  221.     Loop   SendCRLF                     ;do more
  222.  
  223. SkipCRLF:                               ;retrieve saved registers
  224.     Mov    AX, LastCharacter             ;last character value
  225.     Mov    CX, CharCounter               ;character counter
  226.  
  227. APCRExit:
  228.     Mov    LastCRLF,0                   ;reset crlf counter
  229.     Dec    SI                           ;back up a character
  230.     Inc    CX                           ;add that retrieved character
  231.     Clc
  232.     RetN
  233.     
  234. APCRErrExit:
  235.     Dec    SI
  236.     Inc    CX
  237.     Stc
  238.     RetN
  239.  
  240. AMIExit:                                ;--- Main Exit
  241.     Ret
  242.  
  243. AMIProCVT  EndP
  244.